import { Body, Controller, Post } from "@nestjs/common";
import { DicomService } from "./dicom.service";
import { WatchFileService } from "../watch-file/watch-file.service";
import { AppGateway } from "../app/app.gateway";

interface reqType {
  scanId: number | string,
  scoutId: any
  watchFilePath: string,
  totalImgCount: number,
  scanType: string,
}

@Controller("dicom")
export class DicomController {
  constructor(
    private readonly panelService: DicomService,
    private readonly watchFileService: WatchFileService,
    private readonly appGateway: AppGateway
  ) {
  }

  @Post("create")
  async handleScan(@Body() scanParams: reqType[]): Promise<string> {
    console.log("收到创建dicom文件夹请求", scanParams);
    // this.mockResponse(scanParams);
    await this.watchFileService.addNewListen(scanParams);
    return "ok";
  }

  mockResponse(scanParams) {
    setTimeout(() => {
      this.appGateway.sendDicomMsg({
        scanId: scanParams[0].scanId,
        scoutId: scanParams[0].scoutId,
        imageIds: {
          studyUID: "1.2.2046.7929.09.1.20230724.105506.19135",
          seriesUID: "1.2.2046.7929.09.1.20230724.105506.07036"
        },
        totalImgCount: 100,
        currentCount: 1,
        currentScanIdFinish: false
      });
    }, 5000);

    if (scanParams.length  === 2){
      setTimeout(() => {
        this.appGateway.sendDicomMsg({
          scanId: scanParams[1].scanId,
          scoutId: scanParams[1].scoutId,
          imageIds: {
            studyUID: "1.2.826.0.1.3680043.2.461.13044537.2800407881",
            seriesUID: "1.2.840.113619.2.472.3.2831161356.403.1654067940.232.6295553"
          },
          totalImgCount: 100,
          currentCount: 1,
          currentScanIdFinish: false
        });
      }, 5000);
    }

  }

}
